<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../../css/reset.css" />
    <link rel="stylesheet" type="text/css" href="../../css/login.css" />
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../../img/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">使用手机号登陆</li>
                <li></li>
            </ul>
           
                <input style="margin-top: 0;" type="text" name="tel" class="tel" id="username" placeholder="请输入您的手机号">
                <input type="password" name="pass" class="pass" id="password" placeholder="请输入密码">
                <span class="tips">密码或账号不对</span>
                <button class="loginbtn">
                    登陆
                </button>
                
            <p>
                <span>
                    还没有账号?
                    <a href="./register.html">点击注册</a>
                </span>
            </p>
        </div>
    </div>
    <!-- <script src="../../utils/utils.js"></script> -->
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script src="../../utils/myajax.js"></script>
    <script>
        $('.loginbtn').click( async function(){
            let username = $('#username').val()
            let password = $('#password').val()
            let tips= $('.tips')
            console.log(username,password);
            if (!username || !password) {
                tips.text('请填写用户名密码')
                return
            }
            let res = await myAjax({
                url: '/api/login',
                method: 'post',
                data: {
                    username,
                    password
                }
            })
            console.log(res);
            localStorage.setItem('mid', res.result.mid)
            localStorage.setItem('token', res.result.token)
            tips.text(res.result.msg == 'OK'? '登录成功' : res.result.msg)

            setTimeout(function(){

                location.href = 'javascript:history.go(-1)'
            },1000)
        })
    </script>
</body>
</html>